// import Cookies from 'js-cookie'

export const TOKEN_KEY = 'token';

// export const SET_TOKEN = (token:string) => {
//   Cookies.set(TOKEN_KEY, token, { expires: cookieExpires || 1 })
// }

// export const getToken = () => {
//   const token = Cookies.get(TOKEN_KEY)
//   if (token) return token
//   else return false
// }
interface MenuOptions {
  path: string;
  name: string;
  component?: string | (() => Promise<unknown>);
  redirect?: string;
  meta: MetaProps;
  children?: MenuOptions[];
}
interface MetaProps {
  icon: string;
  title: string;
  activeMenu?: string;
  isLink?: string;
  isHide: boolean;
  isFull: boolean;
  isAffix: boolean;
  isKeepAlive: boolean;
}
/**
 * @description 使用递归扁平化菜单，方便添加动态路由
 * @param {Array} menuList 菜单列表
 * @returns {Array}
 */
export const getFlatMenuList = (menuList: any): Array<any> => {
  let newMenuList = JSON.parse(JSON.stringify(menuList));
  return newMenuList.flatMap((item: { children: any; }) => [item, ...(item.children ? getFlatMenuList(item.children) : [])]);
}
/**
 * @description 使用递归过滤出需要渲染在左侧菜单的列表 (需剔除 isHide == true 的菜单)
 * @param {Array} menuList 菜单列表
 * @returns {Array}
 * */
export function getShowMenuList(menuList: any) {
  let newMenuList = JSON.parse(JSON.stringify(menuList));
  return newMenuList.filter((item:any) => {
    item.children?.length && (item.children = getShowMenuList(item.children));
    return !item.meta?.isHide;
  });
}